USE [master]
GO

/****** Object Database : [SGLDBMP01]    
		Script Date		: 10/12/2016 
		Created By		: <<Gokul, G: gokul.g@hotmail.com>>	******/
		
DECLARE @dbName		VARCHAR(15);
SET		@dbName		= N'SGLDBMP01';
		
IF  EXISTS (SELECT [name] FROM sys.databases WHERE name = @dbName)
	BEGIN TRY		-- BG/ED-TY#01
	
		DROP DATABASE [SGLDBMP01]
		PRINT	'Database: ' + @dbName + ' dropped successfully'
		
	END	TRY			-- BG/ED-TY#01
	BEGIN CATCH		-- BG/ED-CT#01
	
		DECLARE @ErrorNumber INT				= ERROR_NUMBER();
		DECLARE @ErrorLine INT					= ERROR_LINE();
		DECLARE @ErrorMessage NVARCHAR(4000)	= ERROR_MESSAGE();
		DECLARE @ErrorSeverity INT				= ERROR_SEVERITY();
		DECLARE @ErrorState INT					= ERROR_STATE();
		DECLARE @ErrorProcedure VARCHAR(100)	= ERROR_PROCEDURE();
			
		PRINT 'Actual Error Number: ' + CAST(@ErrorNumber AS VARCHAR(10));
		PRINT 'Actual Line Number: ' + CAST(@ErrorLine AS VARCHAR(10));
		PRINT 'Error Message: ' + @ErrorMessage;
		PRINT 'Additional Information: Severity: (' + ISNULL(CAST(@ErrorSeverity AS VARCHAR(10)), '-') + ') ' + 
				'Error State: (' + ISNULL(CAST(@ErrorState AS VARCHAR(10)), '-') + ') ' + 
				'ErrorProcedure : (' + ISNULL(@ErrorProcedure, '-') + ')';
		PRINT 'Application Error: Unable to DROP Database: ' + @dbName + '. Please check.'
	END	CATCH		-- BG/ED-CT#01
ELSE
	BEGIN
		PRINT	'Database: ' + @dbName + ' doesnot exists in this SQL Instance: ' + @@SERVERNAME;
	END
GO

USE [master]
GO

/*	OP: Database: SGLDBMP01 dropped successfully
	OP: Database: SGLDBMP01 doesnot exists in this SQL Instance: PC212454
	OP: Actual Error Number: 3702
		Actual Line Number: 12
		Error Message: Cannot drop database "SGLDBMP01" because it is currently in use.
		Additional Information: Severity: (16) Error State: (4) ErrorProcedure : (-)
		Application Error: Unable to DROP Database: SGLDBMP01. Please check.
*/